package com.tudouji.project.handover.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.handover.domain.HandoverRecord;
import com.tudouji.project.handover.service.IHandoverRecordService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 工作移交记录Controller
 * 
 * @author tudouji
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/handover/record")
public class HandoverRecordController extends BaseController
{
    @Autowired
    private IHandoverRecordService handoverRecordService;

    /**
     * 查询工作移交记录列表
     */
    @PreAuthorize("@ss.hasPermi('handover:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(HandoverRecord handoverRecord)
    {
        startPage();
        List<HandoverRecord> list = handoverRecordService.selectHandoverRecordList(handoverRecord);
        return getDataTable(list);
    }

    /**
     * 导出工作移交记录列表
     */
    @PreAuthorize("@ss.hasPermi('handover:record:export')")
    @Log(title = "工作移交记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HandoverRecord handoverRecord)
    {
        List<HandoverRecord> list = handoverRecordService.selectHandoverRecordList(handoverRecord);
        ExcelUtil<HandoverRecord> util = new ExcelUtil<HandoverRecord>(HandoverRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取工作移交记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('handover:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(handoverRecordService.selectHandoverRecordById(id));
    }

    /**
     * 新增工作移交记录
     */
    @PreAuthorize("@ss.hasPermi('handover:record:add')")
    @Log(title = "工作移交记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HandoverRecord handoverRecord)
    {
        return toAjax(handoverRecordService.insertHandoverRecord(handoverRecord));
    }

    /**
     * 修改工作移交记录
     */
    @PreAuthorize("@ss.hasPermi('handover:record:edit')")
    @Log(title = "工作移交记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HandoverRecord handoverRecord)
    {
        return toAjax(handoverRecordService.updateHandoverRecord(handoverRecord));
    }

    /**
     * 删除工作移交记录
     */
    @PreAuthorize("@ss.hasPermi('handover:record:remove')")
    @Log(title = "工作移交记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(handoverRecordService.deleteHandoverRecordByIds(ids));
    }

    /**
     * 交接
     * @param fromUserId
     * @param toUserId
     * @return
     */
    @PostMapping("/trans")
    public AjaxResult trans(Long fromUserId,Long toUserId,String remark,String ftdIDs){
        return handoverRecordService.trans(fromUserId, toUserId, remark,ftdIDs);
    }
}
